home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Aminet 40
/
Aminet 40 (2000)(Schatztruhe)[!][Dec 2000].iso
/
Aminet
/
comm
/
tcp
/
rxsocket.lha
/
rxsocket
/
Examples
/
authfun.rexx
< prev
next >
Wrap
OS/2 REXX Batch file
|
1999-05-29
|
1KB
|
48 lines
/*
This is an auth function.
It wants 3 arguments:
- ha the remote host
- lp the localport number
- sp the remoteport number
Auth is a tcp service which gives informations about a
connession.
Let's suppose someone connected you on tcp port 4000, like in
revserv.rexx. If you want to know who it is you can try auth
service.
The function returns a string beginning with:
+OK it was able to connect the auth service
-ERR an error occurred (e.g. connection refused)
*/
parse arg ha, lp, sp
say ha lp sp
sin.addrFamily = "INET"
sin.addrAddr = ha
if GetServByName("SE","auth","tcp")<0 then sin.addrPort = se.servPort
else sin.addrPort = 113
say sin.addrFamily sin.addrAddr sin.addrPort
sock = socket("INET","STREAM",0)
if sock<0 then exit "-ERR 1"
if connect(sock,"SIN")<0 then exit "-ERR 2"
request = lp "," sp || d2c(13) || d2c(10)
res = send(sock,request)
if res ~= length(request) then "-ERR 3"
ans=""
len = recv(sock,"BUF",1)
do while len>0
ans = ans || buf
len = recv(sock,"BUF",256)
end
if len<0 then exit "-ERR 4" errno()
call CloseSocket(sock)
return "+OK " || left(ans,length(ans)-1)